//
//  SceneDelegate.swift
//  GodShopApp
//
//  Created by apple on 2020/3/26.
//  Copyright © 2020 xidian. All rights reserved.
//

import UIKit
import SwiftUI
import ESTabBarController_swift


class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
      
        if let windowScene = scene as? UIWindowScene {
            
            let window = UIWindow(windowScene: windowScene)
            let tab = self.customIrregularityStyle(delegate: self as? UITabBarControllerDelegate)
            window.rootViewController = tab
            self.window = window
            window.makeKeyAndVisible()
            // 静态图片引导页
            // self.setStaticGuidePage()
            // 动态图片引导页
            //self.setDynamicGuidePage()
            // 视频引导页
            //self.setVideoGuidePage()
            
        }
        
    }
    
     
    func setStaticGuidePage() {
        let imageNameArray: [String] = ["lead01", "lead02", "lead03"]
        let guideView = HHGuidePageHUD.init(imageNameArray: imageNameArray, isHiddenSkipButton: false)
        self.window?.rootViewController?.view.addSubview(guideView)
    }
    
    func setDynamicGuidePage() {
        let imageNameArray: [String] = ["guideImage6.gif", "guideImage7.gif", "guideImage8.gif"]
        let guideView = HHGuidePageHUD.init(imageNameArray: imageNameArray, isHiddenSkipButton: false)
        self.window?.rootViewController?.view.addSubview(guideView)
    }
    
    func setVideoGuidePage() {
        let urlStr = Bundle.main.path(forResource: "qidong.mp4", ofType: nil)
        let videoUrl = NSURL.fileURL(withPath: urlStr!)
        let guideView = HHGuidePageHUD.init(videoURL: videoUrl, isHiddenSkipButton: false)
        self.window?.rootViewController?.view.addSubview(guideView)
    }

     // 加载底部tabbar样式
    func customIrregularityStyle(delegate: UITabBarControllerDelegate?) -> ESTabBarController {
        
        let tabBarController = ESTabBarController()
        
        tabBarController.delegate = delegate
        tabBarController.title = "Irregularity"
        tabBarController.tabBar.shadowImage = UIImage(named: "transparent")
        tabBarController.shouldHijackHandler = {
            tabbarController, viewController, index in
             return false
        }
        
        tabBarController.didHijackHandler = {

            tabbarController, viewController, index in
    
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
                
            }
            
         }
        
        let v1 = HomeViewController()
        let v2 = GoodsViewController()
        let v3 = CouponViewController()
        let v4 = PersonViewController()
      
        
        v1.tabBarItem = ESTabBarItem.init(YYBouncesContentView(), title: "首页", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        v2.tabBarItem = ESTabBarItem.init(YYBouncesContentView(), title: "我听", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        v3.tabBarItem = ESTabBarItem.init(YYBouncesContentView(), title: nil, image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        v4.tabBarItem = ESTabBarItem.init(YYBouncesContentView(), title: "我的", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        
        let n1 = YYNavigationController.init(rootViewController: v1)
        let n2 = YYNavigationController.init(rootViewController: v2)
        let n3 = YYNavigationController.init(rootViewController: v3)
        let n4 = YYNavigationController.init(rootViewController: v4)

        v1.title = "首页"
        v2.title = "我听"
        v3.title = "播放"
        v4.title = "我的"
        
        tabBarController.viewControllers = [n1, n2, n3, n4]
        
        return tabBarController
        
    }
          

    func sceneDidDisconnect(_ scene: UIScene) {
      
    }

    func sceneDidBecomeActive(_ scene: UIScene) {
       
    }

    func sceneWillResignActive(_ scene: UIScene) {
     
        
    }

    func sceneWillEnterForeground(_ scene: UIScene) {
     
    }

    func sceneDidEnterBackground(_ scene: UIScene) {
      
        
        
    }


}

